package school.controller.admin;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import school.domain.Goods;
import school.mapper.OrdersMapper;
import school.support.BaseController;
import school.support.pojo.OrdersPojo;
import school.support.util.ParamUtils;
import tk.mybatis.mapper.entity.Example;

@Controller
@RequestMapping("admin/order")
public class AdminOrderController extends BaseController {

    @Autowired
    private OrdersMapper ordersMapper;

    @RequestMapping("list")
    public String list(String goodsname,String username, @RequestParam(defaultValue = "1") Integer pageNum, Model model){
        Example example = new Example(Goods.class);
        Example.Criteria criteria = example.createCriteria();
        if (goodsname != null) {
            criteria.andCondition("g.name like '%" + goodsname + "%'");
        }
        if (username != null) {
            criteria.andCondition("u.name like '%" + username + "%'");
        }
        PageHelper.startPage(pageNum, pageSize);
        PageInfo<OrdersPojo> pageInfo = new PageInfo<>(ordersMapper.selectPoByExample(example),5);
        model.addAttribute(pageInfo);
        model.addAttribute("url", request.getRequestURI() + "?" + ParamUtils.params2String(request));
        return "admin/order/list";
    }

}
